function userLogin(){
	
	if($("#username").val()==""){
		$("msg").removeAttr("display");
		$("#msg").html("请输入用户名!");
		$("#msg").css("color","red");
		
		$("#username").focus(function(){
			$("#msg").html("");
		});
		return;
	}
	
	if($("#password").val()==""){
		$("msg").removeAttr("display");
		$("#msg").html("请输入密码!");
		$("#msg").css("color","red");
		
		$("#password").focus(function(){
			$("#msg").html("");
		});
		return;
	}
	
	var data={"username":$("#username").val(),"password":$("#password").val()}
	$.ajax({
		"url":"/zhgl-jzstyxx-manage/user/handlelogin.do",
		"data":data,
		"type":"POST",
		"dataType":"json",
		"success":function(obj){
			if(obj.state==1){
				//登录成功,保存cookie
				saveCookie();
				//跳转到主页面
				console.log("aaaaaaaaaaaaaaaaaaa");
				location.href="../index/toIndex";
			}else{
				//登录失败
				$("#msg").html("账号或密码错误");
				$("#msg").css("color","red");
			}
			
		}
	});

}


//记住用户名密码
function saveCookie(){
	//判断是否勾选了记住密码
	var checked =$("#ck_rmbUser").prop("checked");
	if(checked){
		//勾选了记住密码
		var str_username=$("#username").val();
		var str_password=$("#password").val();
		//在cookie中记录“自动登录","用户名","密码"
		console.log("str_username:"+str_username);
		$.cookie("rmbUser","true",{expires:7});//保存七天
		$.cookie("username",str_username,{expires:7});
		$.cookie("password",str_password,{expires:7});
		//把登录信息保存在session中
		var username=str_username;
		var password=str_password;
		$.session.set('username',username);
		$.session.set('right',"系统管理员");
		$.session.set('password',password);
	}else{
		//没有勾选自动登录
		$.cookie("rmbUser","false",{expires:-1});//保存七天
		$.cookie("username","",{expires:-1});
		$.cookie("password","",{expires:-1});
	}
}

$("document").ready(function(){
	//页面加载完毕，查找cookie中是否有自动登录
	if($.cookie("rmbUser")=="true"){
		$("#ck_rmbUser").attr("checked",true);
		$("#username").val($.cookie("username"));
		$("#password").val($.cookie("password"));
		
	}
});
	